using Config;
using Entity;
using MoonFramework.Buff;
using MoonFramework.Scripts.Event;
using MoonFramework.Scripts.Tool;
using MoonFramework.Template;
using Tool;
using Tool.Name;
using UnityEngine;

namespace Map.MapObject.PickUpObject
{
    public class BasePickUpMapObject : BaseMapObject
    {
        [SerializeField] protected int _pickupConfigID;
        protected bool _isStart;
        
        public override bool DoHit(Actor actor, float dir)
        {
            if (dir >= 1f) return false;
            if (actor is Character player)
                if (player.buffFsm.CheckBuff(nameof(DisarmBuff)) ||
                    player.WeaponController.CurrentWeapon.WeaponData != null)
                    return false;
            if (_isStart) return true;
            EventCenter.Instance.Register<ItemWeaponInfo>(EventName.Hurt);
            EventCenter.Instance.SendCommand<ItemWeaponInfo>(EventName.Hurt, Hurt);
            _isStart = true;
            return true;
        }

        public override void Hurt(ItemWeaponInfo weaponInfo)
        {
            Dead();
        }

        protected override void Dead()
        {
            EventCenter.Instance.Callback(EventName.AddItem, _pickupConfigID);
            EventCenter.Instance.RemoveCommand<ItemWeaponInfo>(EventName.Hurt, Hurt);
            RemoveOnMap();
            gameObject.MoonGameObjPushPool();
            _isStart = false;
        }
    }
}